package com.qike.baoxiu.controller;

import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import com.qike.baoxiu.config.PassToken;
import com.qike.baoxiu.dto.*;
import com.qike.baoxiu.pojo.*;
import com.qike.baoxiu.response.BaseResult;
import com.qike.baoxiu.response.RetResponse;
import com.qike.baoxiu.service.OrderService;
import com.qike.baoxiu.service.UserService;
import com.qike.baoxiu.tools.ExcleUtil;
import com.qike.baoxiu.tools.QRCodeUtil;
import com.qike.baoxiu.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@Api(description = "后台接口")
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private UserService userService;

    @Autowired
    private OrderService orderService;


    /**
     * 登录
     *
     * @param loginDto
     * @return
     */
    @ApiOperation("登录")
    @PostMapping("/Login")
    @ResponseBody
    @PassToken
    public BaseResult Login(@RequestBody LoginDto loginDto) {
        try {
            LoginVo vo = userService.login(loginDto);
            return RetResponse.makeOKRsp(vo);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 列表头部统计数据
     *
     * @return
     */
    @ApiOperation("列表头部统计数据")
    @GetMapping("/count")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
    @ResponseBody
    public BaseResult count() {
        try {
            OrderCountVo orderCountVo = orderService.OrderCount();
            return RetResponse.makeOKRsp(orderCountVo);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 维修单列表
     *
     * @return
     */
    @ApiOperation("维修单列表")
    @GetMapping("/orderList")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
    @ResponseBody
    public BaseResult orderList(OrderListDto orderListDto) {
        try {

//            aaaassss
            OrderListVo vo = orderService.orderList(orderListDto);
            return RetResponse.makeOKRsp(vo);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 接单
     *
     * @return
     */
    @ApiOperation("接单")
    @PostMapping("/accecptOrder")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
    @ResponseBody
    public BaseResult accecptOrder(@RequestBody AccecptOrderDto accecptOrderDto) {
        try {
             orderService.accecptOrder(accecptOrderDto);
            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 派单
     *
     * @return
     */
    @ApiOperation("派单")
    @PostMapping("/sendOrder")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
    @ResponseBody
    public BaseResult sendOrder(@RequestBody AccecptOrderDto accecptOrderDto) {
        try {
            orderService.sendOrder(accecptOrderDto);
            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 根据车辆id打印二维码
     *
     * @return
     */
    @GetMapping("/getQRByUserId")
    @ApiOperation("根据车辆id打印二维码")
    public void getQRByCarId(Integer userId, HttpServletResponse response, HttpServletRequest request) throws IOException {
        ServletOutputStream stream = null;
        try {
            stream = response.getOutputStream();
//            String logoPath = "/file/logo.png";
//            String logoPath = ConvertTemplatePath.convertTemplatePath("/file/logo.png");
//            String logoPath = ResourceUtils.getFile("/file/logo.png").getPath();
            //使用工具类生成二维码
            GetQRByCarIdVo   getQRByCarIdVo = orderService.getQRByCarIdVo(userId);
//            String code = request.getParameter("code");
            String url = "https://baoxiu.allin-china.com?account="+getQRByCarIdVo.getAccount()+"&pwd="+getQRByCarIdVo.getPwd();
            QRCodeUtil.encode(url, "/file/logo.png", stream, true,getQRByCarIdVo.getOrg());
        } catch (Exception e) {
            System.out.println(e.getMessage());
        } finally {
            if (stream != null) {
                stream.flush();
                stream.close();
            }

        }
    }


    /**
     * 维修单详情
     *
     * @return
     */
    @ApiOperation("维修单详情")
    @GetMapping("/orderInfo")
    @ResponseBody
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
    public BaseResult orderInfo(Integer id) {
        try {
            OrderInfoVo vo = orderService.orderInfo(id);
            return RetResponse.makeOKRsp(vo);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 添加维修单
     *
     * @return
     */
    @ApiOperation("添加维修单")
    @PostMapping("/addOrder")
    @ResponseBody
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
    public BaseResult addOrder(@RequestBody AddOrderDto addOrderDto) {
        try {
            orderService.addOrder(addOrderDto);
            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }



    /**
     * 添加维修单
     *
     * @return
     */
    @ApiOperation("删除维修单 已完成没有删除按钮")
    @DeleteMapping("/delOrder")
    @ResponseBody
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
    public BaseResult delOrder( Integer id) {
        try {
            orderService.delOrder(id);
            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }


    /**
     * 人员管理列表
     *
     * @return
     */
    @ApiOperation("人员管理列表")
    @GetMapping("/fixUserList")
    @ResponseBody
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
    public BaseResult fixUserList(FixUserListDto fixUserListDto) {
        try {
            FixUserListVo vo = orderService.fixUserList(fixUserListDto);
            return RetResponse.makeOKRsp(vo);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }


    /**
     * 工程师列表
     *
     * @return
     */
    @ApiOperation("工程师列表")
    @GetMapping("/engineList")
    @ResponseBody
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
    public BaseResult engineList(String name) {
        try {
            List<User> vo = orderService.engineList(name);
            return RetResponse.makeOKRsp(vo);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }


    /**
     * 用户管理列表
     *
     * @return
     */
    @ApiOperation("用户管理列表")
    @GetMapping("/UserList")
    @ResponseBody
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
    public BaseResult UserList(FixUserListDto fixUserListDto) {
        try {
            FixUserListVo vo = orderService.UserList(fixUserListDto);
            return RetResponse.makeOKRsp(vo);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 下拉列表
     *
     * @return
     */
    @ApiOperation("下拉列表  role 角色 1 工程师 2 用户")
    @GetMapping("/UserListMenu")
    @ResponseBody
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
    public BaseResult UserListMenu(String phone, Integer role) {
        try {
            List<UserListMenuVo> vo = orderService.UserListMenu(phone, role);
            return RetResponse.makeOKRsp(vo);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 停用用户
     *
     * @return
     */
    @ApiOperation("人员启用/停用")
    @PostMapping("/delFixUser")
    @ResponseBody
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
    public BaseResult delFixUser(@RequestBody Integer id) {
        try {
            orderService.delUser(id);
            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 添加人员
     *
     * @return
     */
    @ApiOperation("添加人员")
    @PostMapping("/addFixUser")
    @ResponseBody
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
    public BaseResult addFixUser(@RequestBody AddFixUserDto addFixUserDto) {
        try {
            orderService.addFixUser(addFixUserDto);
            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 添加用户
     *
     * @return
     */
    @ApiOperation("添加用户")
    @PostMapping("/addUser")
    @ResponseBody
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
    public BaseResult addUser(@RequestBody AddUserDto addUserDto) {
        try {
            orderService.addUser(addUserDto);
            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 添加用户
     *
     * @return
     */
    @ApiOperation("编辑用户")
    @PostMapping("/editUser")
    @ResponseBody
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
    public BaseResult editUser(@RequestBody EditUserDto editUserDto) {
        try {
            orderService.editUser(editUserDto);
            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 报修历史
     *
     * @return
     */
    @ApiOperation("报修历史")
    @GetMapping("/orderHistory")
    @ResponseBody
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
    public BaseResult orderHistory(Integer userId) {
        try {
            List<OrderHistoryVo> orderHistoryVos = orderService.orderHistory(userId);
            return RetResponse.makeOKRsp(orderHistoryVos);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 设备管理详情
     *
     * @return
     */
    @ApiOperation("设备管理详情")
    @GetMapping("/deviceInfo")
    @ResponseBody
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
    public BaseResult deviceInfo(Integer userId) {
        try {
            UserDevice vo = orderService.deviceInfo(userId);
            return RetResponse.makeOKRsp(vo);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 设备管理编辑
     *
     * @return
     */
    @ApiOperation("设备管理编辑")
    @PostMapping("/deviceEdit")
    @ResponseBody
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
    public BaseResult deviceEdit(@RequestBody UserDevice userDevice) {
        try {
            orderService.deviceEdit(userDevice);
            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }


    /**
     * 知识库列表
     *
     * @return
     */
    @ApiOperation("知识库列表")
    @GetMapping("/knowledgeList")
    @ResponseBody
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
    public BaseResult knowledgeList(KnowledgeListDto knowledgeListDto) {
        try {
            KnowledgeListVo vo = orderService.knowledgeList(knowledgeListDto);
            return RetResponse.makeOKRsp(vo);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 添加知识库
     *
     * @return
     */
    @ApiOperation("添加知识库")
    @GetMapping("/knowledgeAdd")
    @ResponseBody
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
    public BaseResult knowledgeAdd(KnowledgeAddDto knowledgeListDto) {
        try {
            orderService.knowledgeAdd(knowledgeListDto);
            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }


    /**
     * 知识库详情
     *
     * @return
     */
    @ApiOperation("知识库详情")
    @GetMapping("/knowledgeInfo")
    @ResponseBody
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
    public BaseResult knowledgeInfo(Integer id) {
        try {
            KnowledgeWithBLOBs knowledge =  orderService.knowledgeInfo(id);
            return RetResponse.makeOKRsp(knowledge);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 删除知识库
     *
     * @return
     */
    @ApiOperation("删除知识库")
    @PostMapping("/knowledgeDel")
    @ResponseBody
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
    public BaseResult knowledgeDel(@RequestBody Integer id) {
        try {
            orderService.knowledgeDel(id);
            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 编辑知识库
     *
     * @return
     */
    @ApiOperation("编辑知识库")
    @PostMapping("/knowledgeEdit")
    @ResponseBody
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
    public BaseResult knowledgeEdit(@RequestBody KnowledgeEditDto knowledgeEditDto) {
        try {
            orderService.knowledgeEdit(knowledgeEditDto);
            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 解决方案列表
     *
     * @return
     */
    @ApiOperation("解决方案列表")
    @GetMapping("/fixList")
    @ResponseBody
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
    public BaseResult fixList(FixListDto fixListDto) {
        try {
            FixListVo fixListVo = orderService.fixList(fixListDto);
            return RetResponse.makeOKRsp(fixListVo);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 解决方案变更状态
     *
     * @return
     */
    @ApiOperation("解决方案变更状态 '0 未确认 1 确认 2 忽略")
    @PostMapping("/fixOrderChangeStatus")
    @ResponseBody
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
//    public BaseResult fixOrderChangeStatus(@RequestBody Integer id,Integer status) {
    public BaseResult fixOrderChangeStatus(@RequestBody FixOrderChangeStatus fixOrderChangeStatus) {
        try {
            orderService.fixOrderChangeStatus(fixOrderChangeStatus.getId(), fixOrderChangeStatus.getStatus());
            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }


    /**
     * 上传图片
     *
     * @return
     */
    @ApiOperation("上传图片")
    @PostMapping("/upLoadPhoto")
    @ResponseBody
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
    public BaseResult upLoadPhoto(@RequestBody MultipartFile file) {
        try {
            String url = orderService.upLoadPhoto(file);
            return RetResponse.makeOKRsp(url);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }


    /**
     * 保修单统计报表
     *
     * @return
     */
    @ApiOperation("保修单统计报表")
    @GetMapping("/fixOrderCount")
    @ResponseBody
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
    public BaseResult fixOrderCount(FixOrderCountDto fixOrderCountDto) {
        try {
            List<FixOrderCountVo> list = orderService.fixOrderCount(fixOrderCountDto);
            return RetResponse.makeOKRsp(list);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 报修单统计报表1
     *
     * @return
     */
    @ApiOperation("报修单统计报表下载")
    @GetMapping("/fixOrderCountDownLoad")
//    @ResponseBody
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
    public BaseResult fixOrderCountDownLoad(FixOrderCountDto fixOrderCountDto, HttpServletResponse httpServletResponse) {
        try {
            List<FixOrderCountDownLoadVo> list = orderService.fixOrderCountDownLoad(fixOrderCountDto);
            List<CountDownLoadVo> list2 = orderService.countDownLoad(fixOrderCountDto);
//            ExcleUtil.exportExcel(list,"报修单统计报表","sheet1",FixOrderCountDownLoadVo.class,"报修单统计报表"+".xls",httpServletResponse);
//            ExcleUtil.exportExcel(list,"来源渠道统计报表","sheet1",FixOrderCountVo.class,"来源渠道统计报表"+".xls",httpServletResponse);
            ExportParams exportParamsPerson = new ExportParams("报修单统计报表","报修单统计", ExcelType.XSSF);
            ExportParams exportParamsOrg = new ExportParams("统计数据","统计数据", ExcelType.XSSF);
            // 创建sheet1使用得map
            Map<String, Object> personMap = new HashMap<>(4);
            // title的参数为ExportParams类型
            personMap.put("title", exportParamsPerson);
            // 模版导出对应得实体类型
            personMap.put("entity", FixOrderCountDownLoadVo.class);
            // sheet中要填充得数据
            personMap.put("data", list);

            // 创建sheet2使用得map
            Map<String, Object> dutyDataMap = new HashMap<>(4);
            dutyDataMap.put("title", exportParamsOrg);
            dutyDataMap.put("entity", CountDownLoadVo.class);
            dutyDataMap.put("data", list2);
            // 将sheet1和sheet2使用得map进行包装
            List<Map<String, Object>> sheetsList = new ArrayList<>();
            sheetsList.add(personMap);
            sheetsList.add(dutyDataMap);
            ExcleUtil.mutiExportExcel(sheetsList,"报修单统计报表"+".xls",httpServletResponse);

            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }





    /**
     * 来源渠道统计报表
     *
     * @return
     */
    @ApiOperation("来源渠道统计报表下载")
    @GetMapping("/fromCountDownLoad")
//    @ResponseBody
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
    public BaseResult fromCountDownLoad(FromCountDto fromCountDto, HttpServletResponse httpServletResponse) {
        try {
            FixOrderCountDto fixOrderCountDto = new FixOrderCountDto();
            fixOrderCountDto.setStart(fromCountDto.getStart());
            fixOrderCountDto.setEnd(fromCountDto.getEnd());
            List<FixOrderCountDownLoadVo> list = orderService.fixOrderCountDownLoad(fixOrderCountDto);
            List<CountDownLoadVo> list2 = orderService.countDownLoad(fixOrderCountDto);
//            ExcleUtil.exportExcel(list,"报修单统计报表","sheet1",FixOrderCountDownLoadVo.class,"报修单统计报表"+".xls",httpServletResponse);
//            ExcleUtil.exportExcel(list,"来源渠道统计报表","sheet1",FixOrderCountVo.class,"来源渠道统计报表"+".xls",httpServletResponse);
            ExportParams exportParamsPerson = new ExportParams("报修单统计报表","报修单统计", ExcelType.XSSF);
            ExportParams exportParamsOrg = new ExportParams("统计数据","统计数据", ExcelType.XSSF);
            // 创建sheet1使用得map
            Map<String, Object> personMap = new HashMap<>(4);
            // title的参数为ExportParams类型
            personMap.put("title", exportParamsPerson);
            // 模版导出对应得实体类型
            personMap.put("entity", FixOrderCountDownLoadVo.class);
            // sheet中要填充得数据
            personMap.put("data", list);

            // 创建sheet2使用得map
            Map<String, Object> dutyDataMap = new HashMap<>(4);
            dutyDataMap.put("title", exportParamsOrg);
            dutyDataMap.put("entity", CountDownLoadVo.class);
            dutyDataMap.put("data", list2);
            // 将sheet1和sheet2使用得map进行包装
            List<Map<String, Object>> sheetsList = new ArrayList<>();
            sheetsList.add(personMap);
            sheetsList.add(dutyDataMap);
            ExcleUtil.mutiExportExcel(sheetsList,"报修单统计报表"+".xls",httpServletResponse);

            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 来源渠道统计报表
     *
     * @return
     */
    @ApiOperation("来源渠道统计报表")
    @GetMapping("/fromCount")
    @ResponseBody
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
    public BaseResult fromCount(FromCountDto fromCountDto) {
        try {
            List<FromCountVo> list = orderService.fromCount(fromCountDto);
            return RetResponse.makeOKRsp(list);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 平均响应时间统计报表
     *
     * @return
     */
    @ApiOperation("平均响应时间统计报表")
    @GetMapping("/avgResponseTime")
    @ResponseBody
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
    public BaseResult avgResponseTime(FixOrderCountDto fixOrderCountDto) {
        try {
            List<FixOrderCountVo> list = orderService.avgResponseTimeCount(fixOrderCountDto);
            return RetResponse.makeOKRsp(list);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 平均响应时间统计报表下载
     *
     * @return
     */
    @ApiOperation("平均响应时间统计报表下载")
    @GetMapping("/avgResponseTimeDownLoad")
    @ResponseBody
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
    public BaseResult avgResponseTimeDownLoad(FixOrderCountDto fixOrderCountDto, HttpServletResponse httpServletResponse) {
        try {
            List<FixOrderCountDownLoadVo> list = orderService.fixOrderCountDownLoad(fixOrderCountDto);
            List<CountDownLoadVo> list2 = orderService.countDownLoad(fixOrderCountDto);
//            ExcleUtil.exportExcel(list,"报修单统计报表","sheet1",FixOrderCountDownLoadVo.class,"报修单统计报表"+".xls",httpServletResponse);
//            ExcleUtil.exportExcel(list,"来源渠道统计报表","sheet1",FixOrderCountVo.class,"来源渠道统计报表"+".xls",httpServletResponse);
            ExportParams exportParamsPerson = new ExportParams("报修单统计报表","报修单统计", ExcelType.XSSF);
            ExportParams exportParamsOrg = new ExportParams("统计数据","统计数据", ExcelType.XSSF);
            // 创建sheet1使用得map
            Map<String, Object> personMap = new HashMap<>(4);
            // title的参数为ExportParams类型
            personMap.put("title", exportParamsPerson);
            // 模版导出对应得实体类型
            personMap.put("entity", FixOrderCountDownLoadVo.class);
            // sheet中要填充得数据
            personMap.put("data", list);

            // 创建sheet2使用得map
            Map<String, Object> dutyDataMap = new HashMap<>(4);
            dutyDataMap.put("title", exportParamsOrg);
            dutyDataMap.put("entity", CountDownLoadVo.class);
            dutyDataMap.put("data", list2);
            // 将sheet1和sheet2使用得map进行包装
            List<Map<String, Object>> sheetsList = new ArrayList<>();
            sheetsList.add(personMap);
            sheetsList.add(dutyDataMap);
            ExcleUtil.mutiExportExcel(sheetsList,"报修单统计报表"+".xls",httpServletResponse);

            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 平均完成时间统计报表
     *
     * @return
     */
    @ApiOperation("平均完成时间统计报表")
    @GetMapping("/avgFinishTime")
    @ResponseBody
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
    public BaseResult avgFinishTime(FixOrderCountDto fixOrderCountDto) {
        try {
            List<FixOrderCountVo> list = orderService.avgFinishTimeCount(fixOrderCountDto);
            return RetResponse.makeOKRsp(list);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 平均完成时间统计报表下载
     *
     * @return
     */
    @ApiOperation("平均完成时间统计报表下载")
    @GetMapping("/avgFinishTimeDownLoad")
    @ResponseBody
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
    public BaseResult avgFinishTimeDownLoad(FixOrderCountDto fixOrderCountDto, HttpServletResponse httpServletResponse) {
        try {
            List<FixOrderCountDownLoadVo> list = orderService.fixOrderCountDownLoad(fixOrderCountDto);
            List<CountDownLoadVo> list2 = orderService.countDownLoad(fixOrderCountDto);
//            ExcleUtil.exportExcel(list,"报修单统计报表","sheet1",FixOrderCountDownLoadVo.class,"报修单统计报表"+".xls",httpServletResponse);
//            ExcleUtil.exportExcel(list,"来源渠道统计报表","sheet1",FixOrderCountVo.class,"来源渠道统计报表"+".xls",httpServletResponse);
            ExportParams exportParamsPerson = new ExportParams("报修单统计报表","报修单统计", ExcelType.XSSF);
            ExportParams exportParamsOrg = new ExportParams("统计数据","统计数据", ExcelType.XSSF);
            // 创建sheet1使用得map
            Map<String, Object> personMap = new HashMap<>(4);
            // title的参数为ExportParams类型
            personMap.put("title", exportParamsPerson);
            // 模版导出对应得实体类型
            personMap.put("entity", FixOrderCountDownLoadVo.class);
            // sheet中要填充得数据
            personMap.put("data", list);

            // 创建sheet2使用得map
            Map<String, Object> dutyDataMap = new HashMap<>(4);
            dutyDataMap.put("title", exportParamsOrg);
            dutyDataMap.put("entity", CountDownLoadVo.class);
            dutyDataMap.put("data", list2);
            // 将sheet1和sheet2使用得map进行包装
            List<Map<String, Object>> sheetsList = new ArrayList<>();
            sheetsList.add(personMap);
            sheetsList.add(dutyDataMap);
            ExcleUtil.mutiExportExcel(sheetsList,"报修单统计报表"+".xls",httpServletResponse);

            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 评价统计报表
     *
     * @return
     */
    @ApiOperation("评价统计报表")
    @GetMapping("/scoreCount")
    @ResponseBody
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)})
    public BaseResult scoreCount(ScoreCountDto scoreCountDto) {
        try {
            List<ScoreCountMapVo> list = orderService.scoreCount(scoreCountDto);
            return RetResponse.makeOKRsp(list);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 评价已完成维修单
     *
     * @return
     */
    @ApiOperation("评价已完成维修单 如果已经评价 会返回分数 提交按钮置灰  否则会返回空")
    @PostMapping("/scoreFinishOrder")
    @ResponseBody
    public BaseResult scoreFinishOrder(@RequestBody ScoreFinishOrderDto scoreFinishOrderDto) {
        try {
            Integer score = orderService.scoreFinishOrder(scoreFinishOrderDto);
            return RetResponse.makeOKRsp(score);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }


    /**
     * 父字典列表
     *
     * @return
     */
    @ApiOperation("父字典列表")
    @GetMapping("/directoryList")
    @ResponseBody
    public BaseResult directoryList(String name) {
        try {
            List<Directory> nameList = orderService.directoryList(name);
            return RetResponse.makeOKRsp(nameList);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 子字典列表
     *
     * @return
     */
    @ApiOperation("子字典列表")
    @GetMapping("/sonDirectoryList")
    @ResponseBody
    public BaseResult sonDirectoryList(Integer parentId) {
        try {
            List<Directory> nameList = orderService.sonDirectoryList(parentId);
            return RetResponse.makeOKRsp(nameList);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 全部字典列表
     *
     * @return
     */
    @ApiOperation("全部字典列表")
    @GetMapping("/allDirectoryList")
    @ResponseBody
    public BaseResult allDirectoryList() {
        try {
            List<AllDirectoryListVo> nameList = orderService.allDirectoryList();
            return RetResponse.makeOKRsp(nameList);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }


    /**
     * 软件名称列表
     *
     * @return
     */
    @ApiOperation("软件名称列表")
    @GetMapping("/softNameList")
    @ResponseBody
    public BaseResult softNameList() {
        try {
            List<String> nameList = orderService.softNameList();
            return RetResponse.makeOKRsp(nameList);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 添加字典
     *
     * @return
     */
    @ApiOperation("添加字典")
    @GetMapping("/addDirectory")
    @ResponseBody
    public BaseResult addDirectory(AddDirectoryDto addDirectoryDto) {
        try {
            orderService.addDirectory(addDirectoryDto);
            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 删除字典
     *
     * @return
     */
    @ApiOperation("删除字典")
    @DeleteMapping("/delDirectory")
    @ResponseBody
    public BaseResult delDirectory(Integer id) {
        try {
            orderService.delDirectory(id);
            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 查看月报
     *
     * @return
     */
    @ApiOperation("查看月报")
    @DeleteMapping("/ShowMonthReport")
    @ResponseBody
    public BaseResult ShowMonthReport(Integer uid) {
        try {
            MonthReport monthReport = orderService.ShowMonthReport(uid);
            return RetResponse.makeOKRsp(monthReport);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }
}


